package com.coder.algorithm.leetcode

/**
 * [167. 两数之和 II - 输入有序数组](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/)
 *
 * @author yuhus
 * @date: 2022/3/29
 */
object l_0167 {
    fun twoSum(numbers: IntArray, target: Int): IntArray {
        var index1 = 0
        var index2 = numbers.size - 1
        while (index1 < index2) {
            val sum = numbers[index1] + numbers[index2]
            if (sum == target) {
                return intArrayOf(index1 + 1, index2 + 1)
            } else if (sum < target) {
                index1++
            } else {
                index2--
            }
        }
        return intArrayOf()
    }
}